/**
 * @name Cross-Module Function Calls
 * @kind problem
 * @problem.severity info
 * @description Finds function calls across different modules
 * @id cpp/cross-module-calls
 */

import cpp

from FunctionCall call, Function caller, Function callee
where 
  call.getTarget() = callee
  and caller.getFile().getRelativePath() != callee.getFile().getRelativePath()
  // 排除标准库和系统头文件
  and not callee.getFile().getRelativePath().matches("%/usr/%")
  and not callee.getFile().getRelativePath().matches("%stdlib.h%")
  and not callee.getFile().getRelativePath().matches("%string.h%")
  and not callee.getFile().getRelativePath().matches("%iostream%")
select 
  call.getFile().getRelativePath() as callerFile,
  call.getLocation().getStartLine() as callerLine,
  caller.getName() as callerName,
  callee.getFile().getRelativePath() as calleeFile,
  callee.getLocation().getStartLine() as calleeLine,
  callee.getName() as calleeName,
  "Cross-module call: " + caller.getFile().getRelativePath() + 
    ":" + call.getLocation().getStartLine() + 
    " calls " + callee.getFile().getRelativePath() + 
    ":" + callee.getLocation().getStartLine()

